package com.government.web.controller.tag;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.government.common.annotation.RepeatSubmit;
import com.government.tag.bo.TagBO;
import com.government.tag.vo.TagVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.government.common.annotation.Log;
import com.government.common.core.controller.BaseController;
import com.government.common.core.domain.AjaxResult;
import com.government.common.enums.BusinessType;
import com.government.tag.domain.Tag;
import com.government.tag.service.ITagService;
import com.government.common.utils.poi.ExcelUtil;
import com.government.common.core.page.TableDataInfo;

/**
 * 标签信息Controller
 * 
 * @author system
 * @date 2023-09-13
 */
@RestController
@RequestMapping("/tag/tag")
public class TagController extends BaseController
{
    @Autowired
    private ITagService tagService;

    /**
     * 查询标签信息列表
     */
    @PreAuthorize("@ss.hasPermi('tag:tag:list')")
    @GetMapping("/list")
    public AjaxResult list(Tag tag)
    {
        List<TagVO> list = tagService.selectTagList(tag);
        return success(list);
    }

    /**
     * 导出标签信息列表
     */
    @PreAuthorize("@ss.hasPermi('tag:tag:export')")
    @Log(title = "标签信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Tag tag)
    {
        List<TagVO> list = tagService.selectTagList(tag);
        ExcelUtil<TagVO> util = new ExcelUtil<TagVO>(TagVO.class);
        util.exportExcel(response, list, "标签信息数据");
    }

    /**
     * 获取标签信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('tag:tag:query')")
    @GetMapping(value = "/{tagId}")
    public AjaxResult getInfo(@PathVariable("tagId") Long tagId)
    {
        return success(tagService.selectTagByTagId(tagId));
    }

    /**
     * 新增标签信息
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('tag:tag:add')")
    @Log(title = "标签信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tag tag)
    {
        return toAjax(tagService.insertTag(tag));
    }

    /**
     * 修改标签信息
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('tag:tag:edit')")
    @Log(title = "标签信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tag tag)
    {
        return toAjax(tagService.updateTag(tag));
    }

    /**
     * 删除标签信息
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('tag:tag:remove')")
    @Log(title = "标签信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tagId}")
    public AjaxResult remove(@PathVariable Long tagId)
    {
        return toAjax(tagService.deleteTagByTagId(tagId));
    }

    /**
     * 获取标签树列表
     */
    @GetMapping("/tagSelect")
    public AjaxResult tagSelect(TagBO tag)
    {
        return success(tagService.tagSelect(tag));
    }

}
